package com.example.json.photopicker;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;

import com.jay.ui.PhotoPickerActivity;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private int REQUEST_CODE = 1;
    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.main_iv);
        Intent intent = new Intent(MainActivity.this, PhotoPickerActivity.class);
        //多选 默认单选
//        intent.putExtra(PhotoPickerActivity.IS_MULTI_SELECT, true);
        //多选数量
//        intent.putExtra(PhotoPickerActivity.MAX_SELECT_SIZE, 10);

        startActivityForResult(intent, REQUEST_CODE);

    }

    /*回传接收*/
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
            //单选
            String result = data.getStringExtra(PhotoPickerActivity.SELECT_RESULTS);
            Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
            Bitmap bitmap = BitmapFactory.decodeFile(result);
            imageView.setImageBitmap(bitmap);
            //多选
//            List<String> result= data.getStringArrayListExtra(PhotoPickerActivity.SELECT_RESULTS_ARRAY);
//            Toast.makeText(this, "result:" + result, Toast.LENGTH_SHORT).show();
        }
    }
}
